/**
 * Created : Jun 15, 2012
 *
 * @author pquiring
 */

import java.io.*;
import java.util.*;
import javax.swing.*;

import javaforce.*;

public class MainPanel extends javax.swing.JPanel {

  /**
   * Creates new form MainPanel
   */
  public MainPanel() {
    initComponents();
    Settings.loadSettings();
    main = this;
    clipboardPath = Paths.getClipboardPath();
    new File(clipboardPath).mkdirs();
    ProjectPanel.deleteClipboard();
    newProject();
  }

  /**
   * This method is called from within the constructor to initialize the form.
   * WARNING: Do NOT modify this code. The content of this method is always
   * regenerated by the Form Editor.
   */
  @SuppressWarnings("unchecked")
  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
  private void initComponents() {

    jToolBar1 = new javax.swing.JToolBar();
    pause = new javax.swing.JButton();
    play = new javax.swing.JButton();
    stop = new javax.swing.JButton();
    home = new javax.swing.JButton();
    end = new javax.swing.JButton();
    record = new javax.swing.JButton();
    jSeparator1 = new javax.swing.JToolBar.Separator();
    jSeparator2 = new javax.swing.JToolBar.Separator();
    zoomOut = new javax.swing.JButton();
    zoomIn = new javax.swing.JButton();
    tabs = new javax.swing.JTabbedPane();
    jToolBar2 = new javax.swing.JToolBar();
    jLabel1 = new javax.swing.JLabel();
    mute = new javax.swing.JToggleButton();
    solo = new javax.swing.JToggleButton();
    jSeparator3 = new javax.swing.JToolBar.Separator();
    deleteTrack = new javax.swing.JButton();
    jSeparator4 = new javax.swing.JToolBar.Separator();
    spk = new javax.swing.JLabel();
    playVol = new javax.swing.JSlider();
    mic = new javax.swing.JLabel();
    recVol = new javax.swing.JSlider();
    jSeparator5 = new javax.swing.JToolBar.Separator();
    filler1 = new javax.swing.Box.Filler(new java.awt.Dimension(0, 0), new java.awt.Dimension(0, 0), new java.awt.Dimension(32767, 0));

    jToolBar1.setFloatable(false);
    jToolBar1.setRollover(true);

    pause.setText("Pause");
    pause.setFocusable(false);
    pause.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
    pause.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
    pause.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        pauseActionPerformed(evt);
      }
    });
    jToolBar1.add(pause);

    play.setText("Play");
    play.setFocusable(false);
    play.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
    play.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
    play.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        playActionPerformed(evt);
      }
    });
    jToolBar1.add(play);

    stop.setText("Stop");
    stop.setFocusable(false);
    stop.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
    stop.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
    stop.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        stopActionPerformed(evt);
      }
    });
    jToolBar1.add(stop);

    home.setText("|<");
    home.setFocusable(false);
    home.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
    home.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
    home.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        homeActionPerformed(evt);
      }
    });
    jToolBar1.add(home);

    end.setText(">|");
    end.setFocusable(false);
    end.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
    end.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
    end.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        endActionPerformed(evt);
      }
    });
    jToolBar1.add(end);

    record.setText("Rec");
    record.setFocusable(false);
    record.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
    record.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
    record.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        recordActionPerformed(evt);
      }
    });
    jToolBar1.add(record);
    jToolBar1.add(jSeparator1);
    jToolBar1.add(jSeparator2);

    zoomOut.setText("Zoom-");
    zoomOut.setFocusable(false);
    zoomOut.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
    zoomOut.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
    zoomOut.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        zoomOutActionPerformed(evt);
      }
    });
    jToolBar1.add(zoomOut);

    zoomIn.setText("Zoom+");
    zoomIn.setFocusable(false);
    zoomIn.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
    zoomIn.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
    zoomIn.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        zoomInActionPerformed(evt);
      }
    });
    jToolBar1.add(zoomIn);

    jToolBar2.setFloatable(false);
    jToolBar2.setRollover(true);

    jLabel1.setText("Track:");
    jToolBar2.add(jLabel1);

    mute.setText("mute");
    mute.setFocusable(false);
    mute.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
    mute.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
    mute.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        muteActionPerformed(evt);
      }
    });
    jToolBar2.add(mute);

    solo.setText("solo");
    solo.setFocusable(false);
    solo.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
    solo.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
    solo.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        soloActionPerformed(evt);
      }
    });
    jToolBar2.add(solo);
    jToolBar2.add(jSeparator3);

    deleteTrack.setText("delete");
    deleteTrack.setFocusable(false);
    deleteTrack.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
    deleteTrack.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
    deleteTrack.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        deleteTrackActionPerformed(evt);
      }
    });
    jToolBar2.add(deleteTrack);
    jToolBar2.add(jSeparator4);

    spk.setIcon(new javax.swing.ImageIcon(getClass().getResource("/spk.png"))); // NOI18N
    jToolBar2.add(spk);

    playVol.setValue(100);
    playVol.setMaximumSize(new java.awt.Dimension(100, 23));
    playVol.setMinimumSize(new java.awt.Dimension(100, 23));
    playVol.addChangeListener(new javax.swing.event.ChangeListener() {
      public void stateChanged(javax.swing.event.ChangeEvent evt) {
        playVolStateChanged(evt);
      }
    });
    jToolBar2.add(playVol);

    mic.setIcon(new javax.swing.ImageIcon(getClass().getResource("/mic.png"))); // NOI18N
    jToolBar2.add(mic);

    recVol.setValue(100);
    recVol.setMaximumSize(new java.awt.Dimension(100, 23));
    recVol.setMinimumSize(new java.awt.Dimension(100, 23));
    recVol.addChangeListener(new javax.swing.event.ChangeListener() {
      public void stateChanged(javax.swing.event.ChangeEvent evt) {
        recVolStateChanged(evt);
      }
    });
    jToolBar2.add(recVol);
    jToolBar2.add(jSeparator5);
    jToolBar2.add(filler1);

    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
    this.setLayout(layout);
    layout.setHorizontalGroup(
      layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addComponent(jToolBar1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
      .addComponent(jToolBar2, javax.swing.GroupLayout.DEFAULT_SIZE, 636, Short.MAX_VALUE)
      .addComponent(tabs)
    );
    layout.setVerticalGroup(
      layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(layout.createSequentialGroup()
        .addComponent(jToolBar1, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
        .addComponent(jToolBar2, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
        .addComponent(tabs, javax.swing.GroupLayout.DEFAULT_SIZE, 615, Short.MAX_VALUE))
    );
  }// </editor-fold>//GEN-END:initComponents

  private void zoomOutActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_zoomOutActionPerformed
    ProjectPanel project = (ProjectPanel)tabs.getSelectedComponent();
    project.zoom(-1);
  }//GEN-LAST:event_zoomOutActionPerformed

  private void zoomInActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_zoomInActionPerformed
    ProjectPanel project = (ProjectPanel)tabs.getSelectedComponent();
    project.zoom(+1);
  }//GEN-LAST:event_zoomInActionPerformed

  private void recordActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_recordActionPerformed
    ProjectPanel project = (ProjectPanel)tabs.getSelectedComponent();
    project.record();
    play.setEnabled(false);
    record.setEnabled(false);
    pause.setEnabled(false);
  }//GEN-LAST:event_recordActionPerformed

  private void stopActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_stopActionPerformed
    ProjectPanel project = (ProjectPanel)tabs.getSelectedComponent();
    project.stop();
    play.setEnabled(true);
    record.setEnabled(true);
    play.setEnabled(true);
  }//GEN-LAST:event_stopActionPerformed

  private void playActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_playActionPerformed
    ProjectPanel project = (ProjectPanel)tabs.getSelectedComponent();
    project.play();
    play.setEnabled(false);
    record.setEnabled(false);
  }//GEN-LAST:event_playActionPerformed

  private void deleteTrackActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_deleteTrackActionPerformed
    ProjectPanel project = (ProjectPanel)tabs.getSelectedComponent();
    project.deleteTrack();
  }//GEN-LAST:event_deleteTrackActionPerformed

  private void homeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_homeActionPerformed
    ProjectPanel project = (ProjectPanel)tabs.getSelectedComponent();
    project.gotoHome();
  }//GEN-LAST:event_homeActionPerformed

  private void endActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_endActionPerformed
    ProjectPanel project = (ProjectPanel)tabs.getSelectedComponent();
    project.gotoEnd();
  }//GEN-LAST:event_endActionPerformed

  private void pauseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_pauseActionPerformed
    ProjectPanel project = (ProjectPanel)tabs.getSelectedComponent();
    project.pause();
  }//GEN-LAST:event_pauseActionPerformed

  private void muteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_muteActionPerformed
    ProjectPanel project = (ProjectPanel)tabs.getSelectedComponent();
    if (mute.isSelected()) {
      project.mute();
    } else {
      project.unmute();
      solo.setSelected(false);
    }
  }//GEN-LAST:event_muteActionPerformed

  private void soloActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_soloActionPerformed
    ProjectPanel project = (ProjectPanel)tabs.getSelectedComponent();
    project.solo();
    mute.setSelected(false);
  }//GEN-LAST:event_soloActionPerformed

  private void playVolStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_playVolStateChanged
  }//GEN-LAST:event_playVolStateChanged

  private void recVolStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_recVolStateChanged
  }//GEN-LAST:event_recVolStateChanged

  // Variables declaration - do not modify//GEN-BEGIN:variables
  private javax.swing.JButton deleteTrack;
  private javax.swing.JButton end;
  private javax.swing.Box.Filler filler1;
  private javax.swing.JButton home;
  private javax.swing.JLabel jLabel1;
  private javax.swing.JToolBar.Separator jSeparator1;
  private javax.swing.JToolBar.Separator jSeparator2;
  private javax.swing.JToolBar.Separator jSeparator3;
  private javax.swing.JToolBar.Separator jSeparator4;
  private javax.swing.JToolBar.Separator jSeparator5;
  private javax.swing.JToolBar jToolBar1;
  private javax.swing.JToolBar jToolBar2;
  private javax.swing.JLabel mic;
  private javax.swing.JToggleButton mute;
  private javax.swing.JButton pause;
  private javax.swing.JButton play;
  private javax.swing.JSlider playVol;
  private javax.swing.JSlider recVol;
  private javax.swing.JButton record;
  private javax.swing.JToggleButton solo;
  private javax.swing.JLabel spk;
  private javax.swing.JButton stop;
  private javax.swing.JTabbedPane tabs;
  private javax.swing.JButton zoomIn;
  private javax.swing.JButton zoomOut;
  // End of variables declaration//GEN-END:variables

  public ArrayList<ProjectPanel> projects = new ArrayList<ProjectPanel>();
  public static MainPanel main;
  public static String clipboardPath;

  public void newProject() {
    ProjectPanel project = new ProjectPanel(null);
    tabs.add(project, "New Project");
    projects.add(project);
  }

  public void saveProject() {
    ProjectPanel project = (ProjectPanel)tabs.getSelectedComponent();
    if (project.filename == null) {
      JFileChooser chooser = new JFileChooser();
      chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
      chooser.setMultiSelectionEnabled(false);
      chooser.setCurrentDirectory(new File(JF.getUserPath() + "/Music"));
      javax.swing.filechooser.FileFilter ffProject = new javax.swing.filechooser.FileFilter() {
        public boolean accept(File file) {
          if (file.isDirectory()) return true;
          if (file.getName().endsWith(".aproj")) return true;
          return false;
        }
        public String getDescription() {
          return "Audio Project (*.aproj)";
        }
      };
      chooser.addChoosableFileFilter(ffProject);
      chooser.setFileFilter(chooser.getAcceptAllFileFilter());
      AudioApp.inDialog = true;
      if (chooser.showSaveDialog(this) != JFileChooser.APPROVE_OPTION) {
        AudioApp.inDialog = false;
        return;
      }
      AudioApp.inDialog = false;
      project.filename = chooser.getSelectedFile().getAbsolutePath();
      if (!project.filename.toLowerCase().endsWith(".aproj")) project.filename += ".aproj";
      int idx = project.filename.lastIndexOf(".");
      String newPath = project.filename.substring(0, idx) + "_data";
      try {
        Paths.moveFolder(project.path, newPath);
      } catch (Exception e) {
        JFAWT.showError("Error", "Failed to move project data files");
        project.filename = null;
        return;
      }
      project.path = newPath;
      tabs.setTitleAt(tabs.getSelectedIndex(), project.getTabName());
    }
    project.saveConfig();
  }

  public void renameProject() {
    ProjectPanel project = (ProjectPanel)tabs.getSelectedComponent();
    if (project.filename == null) {
      saveProject();
      return;
    }
    String orgFilename = project.filename;
    project.filename = null;
    saveProject();
    if (project.filename == null) {
      project.filename = orgFilename;
    }
  }

  public void openFile() {
    JFileChooser chooser = new JFileChooser();
    chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    chooser.setMultiSelectionEnabled(false);
    chooser.setCurrentDirectory(new File(JF.getUserPath() + "/Music"));
    javax.swing.filechooser.FileFilter ffWAV = new javax.swing.filechooser.FileFilter() {
      public boolean accept(File file) {
        if (file.isDirectory()) return true;
        if (file.getName().endsWith(".wav")) return true;
        return false;
      }
      public String getDescription() {
        return "WAV (*.wav)";
      }
    };
    chooser.addChoosableFileFilter(ffWAV);
    javax.swing.filechooser.FileFilter ffProject = new javax.swing.filechooser.FileFilter() {
      public boolean accept(File file) {
        if (file.isDirectory()) return true;
        if (file.getName().endsWith(".aproj")) return true;
        return false;
      }
      public String getDescription() {
        return "Audio Project (*.aproj)";
      }
    };
    chooser.addChoosableFileFilter(ffProject);
    chooser.setFileFilter(chooser.getAcceptAllFileFilter());
    AudioApp.inDialog = true;
    if (chooser.showOpenDialog(this) != JFileChooser.APPROVE_OPTION) {
      AudioApp.inDialog = false;
      return;
    }
    AudioApp.inDialog = false;
    String fn = chooser.getSelectedFile().getAbsolutePath();
    closeProjectIfEmpty();
    if (fn.toLowerCase().endsWith(".aproj")) {
      ProjectPanel project = new ProjectPanel(fn);
      tabs.add(project, project.getTabName());
      return;
    }
    ProjectPanel project = new ProjectPanel(null);
    tabs.add(project, "New Project");
    project.importFile(fn);
  }

  public void importFile() {
    JFileChooser chooser = new JFileChooser();
    chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    chooser.setMultiSelectionEnabled(false);
    chooser.setCurrentDirectory(new File(JF.getUserPath() + "/Music"));
    javax.swing.filechooser.FileFilter ffWAV = new javax.swing.filechooser.FileFilter() {
      public boolean accept(File file) {
        if (file.isDirectory()) return true;
        if (file.getName().endsWith(".wav")) return true;
        return false;
      }
      public String getDescription() {
        return "WAV (*.wav)";
      }
    };
    chooser.addChoosableFileFilter(ffWAV);
    javax.swing.filechooser.FileFilter ffFLAC = new javax.swing.filechooser.FileFilter() {
      public boolean accept(File file) {
        if (file.isDirectory()) return true;
        if (file.getName().endsWith(".flac")) return true;
        return false;
      }
      public String getDescription() {
        return "FLAC (*.flac)";
      }
    };
    chooser.addChoosableFileFilter(ffFLAC);
    javax.swing.filechooser.FileFilter ffMP3 = new javax.swing.filechooser.FileFilter() {
      public boolean accept(File file) {
        if (file.isDirectory()) return true;
        if (file.getName().endsWith(".mp3")) return true;
        return false;
      }
      public String getDescription() {
        return "MP3 (*.mp3)";
      }
    };
    chooser.addChoosableFileFilter(ffMP3);
    chooser.setFileFilter(ffWAV);
    AudioApp.inDialog = true;
    if (chooser.showOpenDialog(this) != JFileChooser.APPROVE_OPTION) {
      AudioApp.inDialog = false;
      return;
    }
    AudioApp.inDialog = false;
    String fn = chooser.getSelectedFile().getAbsolutePath();
    ProjectPanel project = (ProjectPanel)tabs.getSelectedComponent();
    project.importFile(fn);
  }

  public void exportFile(boolean selection) {
    ProjectPanel project = (ProjectPanel)tabs.getSelectedComponent();
    if (!project.isTrackSelected()) return;
    JFileChooser chooser = new JFileChooser();
    chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    chooser.setMultiSelectionEnabled(false);
    chooser.setCurrentDirectory(new File(JF.getUserPath() + "/Music"));
    javax.swing.filechooser.FileFilter ffWAV = new javax.swing.filechooser.FileFilter() {
      public boolean accept(File file) {
        if (file.isDirectory()) return true;
        if (file.getName().endsWith(".wav")) return true;
        return false;
      }
      public String getDescription() {
        return "WAV (*.wav)";
      }
      public String toString() {
        return ".wav";
      }
    };
    chooser.addChoosableFileFilter(ffWAV);
    javax.swing.filechooser.FileFilter ffFLAC = new javax.swing.filechooser.FileFilter() {
      public boolean accept(File file) {
        if (file.isDirectory()) return true;
        if (file.getName().endsWith(".flac")) return true;
        return false;
      }
      public String getDescription() {
        return "FLAC (*.flac)";
      }
      public String toString() {
        return ".flac";
      }
    };
    chooser.addChoosableFileFilter(ffFLAC);
    javax.swing.filechooser.FileFilter ffMP3 = new javax.swing.filechooser.FileFilter() {
      public boolean accept(File file) {
        if (file.isDirectory()) return true;
        if (file.getName().endsWith(".mp3")) return true;
        return false;
      }
      public String getDescription() {
        return "MP3 (*.mp3)";
      }
      public String toString() {
        return ".mp3";
      }
    };
    chooser.addChoosableFileFilter(ffMP3);
    chooser.setFileFilter(ffWAV);
    AudioApp.inDialog = true;
    if (chooser.showSaveDialog(this) != JFileChooser.APPROVE_OPTION) {
      AudioApp.inDialog = false;
      return;
    }
    AudioApp.inDialog = false;
    String fn = chooser.getSelectedFile().getAbsolutePath();
    String fnlc = fn.toLowerCase();
    if ((!fnlc.endsWith(".wav")) && !fnlc.endsWith(".flac") && !fnlc.endsWith(".mp3")) {
      javax.swing.filechooser.FileFilter ff = chooser.getFileFilter();
      fn += ff.toString();
    }
    project.exportFile(fn, selection);
  }

  public void close() {
    while (projects.size() > 0) {
      ProjectPanel project = projects.remove(0);
      project.close();
    }
  }

  public void stopped() {
    play.setEnabled(true);
    record.setEnabled(true);
  }

  /** Closes current project. */
  public void closeProject() {
    ProjectPanel project = (ProjectPanel)tabs.getSelectedComponent();
    tabs.remove(project);
    if (tabs.getTabCount() == 0) newProject();
  }

  /** Closes current project and does NOT create a new one. */
  public void closeProjectIfEmpty() {
    ProjectPanel project = (ProjectPanel)tabs.getSelectedComponent();
    if (project.list.isEmpty()) tabs.remove(project);
  }

  public void selectTrack(TrackPanel track) {
    mute.setSelected(track.muted);
    solo.setSelected(false);
  }

  public void stop() {
    stopActionPerformed(null);
  }

  public void cut() {
    ProjectPanel project = (ProjectPanel)tabs.getSelectedComponent();
    project.getSelectedTrack().cut();
  }
  public void copy() {
    ProjectPanel project = (ProjectPanel)tabs.getSelectedComponent();
    project.getSelectedTrack().copy();
  }
  public void paste() {
    ProjectPanel project = (ProjectPanel)tabs.getSelectedComponent();
    project.getSelectedTrack().paste(MainPanel.clipboardPath, true);
  }
  public void delete() {
    ProjectPanel project = (ProjectPanel)tabs.getSelectedComponent();
    project.getSelectedTrack().delete(true);
  }

  public void undo() {
    ProjectPanel project = (ProjectPanel)tabs.getSelectedComponent();
    project.undo();
  }

  public void trackInfo() {
    ProjectPanel project = (ProjectPanel)tabs.getSelectedComponent();
    project.getSelectedTrack().info();
  }

  public void mixTracks() {
    ProjectPanel project = (ProjectPanel)tabs.getSelectedComponent();
    project.mixTracks();
  }

  public void resampleTrack() {
    ProjectPanel project = (ProjectPanel)tabs.getSelectedComponent();
    project.getSelectedTrack().fxResample();
  }

  public void newTrack(int chs) {
    ProjectPanel project = (ProjectPanel)tabs.getSelectedComponent();
    project.newTrack(chs);
  }

  public void fxAmplify() {
    ProjectPanel project = (ProjectPanel)tabs.getSelectedComponent();
    project.getSelectedTrack().fxAmplify();
  }
  public void fxFadeIn() {
    ProjectPanel project = (ProjectPanel)tabs.getSelectedComponent();
    project.getSelectedTrack().fxFadeIn();
  }
  public void fxFadeOut() {
    ProjectPanel project = (ProjectPanel)tabs.getSelectedComponent();
    project.getSelectedTrack().fxFadeOut();
  }
  public void genTone() {
    ProjectPanel project = (ProjectPanel)tabs.getSelectedComponent();
    project.getSelectedTrack().genTone();
  }
  public void genSilence() {
    ProjectPanel project = (ProjectPanel)tabs.getSelectedComponent();
    project.getSelectedTrack().genSilence();
  }
  public int getPlayLevel() {
    return playVol.getValue();
  }
  public int getRecordLevel() {
    return recVol.getValue();
  }
}
